﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Biljart.Model.Localisation;

namespace Biljart.Model.Validator
{
    public class UserValidator
    {
        private readonly List<String> _illegalNames;
        private const int MinimumCharactersUsername = 5;
        private const int MaximumCharactersUsername = 20;

        public UserValidator()
        {
            _illegalNames = new List<String> {"admin", "username", "moderator"};
        }

        public bool ValidateUser(User user)
        {
            //TODO validate an entire user object
            return true;
        }

        public Dictionary<string, ObservableCollection<string>> ValidateUsername(string username)
        {
            var errors = new Dictionary<string, ObservableCollection<string>>();
            errors.Add("UserName", new ObservableCollection<string>());

            if (username.Length > MaximumCharactersUsername)
            {
                errors["UserName"].Add(String.Format(ErrorMessages.ToManyCharacters, FieldNames.UserName, MaximumCharactersUsername));
            }
            if (username.Length < MinimumCharactersUsername)
            {
                errors["UserName"].Add(String.Format(ErrorMessages.ToFewCharacters, FieldNames.UserName, MinimumCharactersUsername));
            }
            if (_illegalNames.Contains(username.ToLower()))
            {
                errors["UserName"].Add(String.Format(ErrorMessages.IllegalName));
            }

            return errors;
        }

    }
}
